# Maintainer: Daniel Bermond <dbermond@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>

pkgbase=level-zero
pkgname=(level-zero-headers level-zero-loader)
pkgver=1.9.4
pkgrel=1
pkgdesc="API for accessing low level interfaces in oneAPI platform devices"
arch=(loong64 x86_64)
url="https://spec.oneapi.com/versions/latest/elements/l0/source/index.html"
license=(MIT)
makedepends=(cmake opencl-headers)
source=(https://github.com/oneapi-src/level-zero/archive/v${pkgver}/${pkgbase}-${pkgver}.tar.gz)
sha256sums=('7f91ed993be1e643c752cf95a319a0fc64113d91ec481fbb8a2f478f433d3380')

prepare() {
  printf '%s\n' ${pkgver##*.} > ${pkgbase}-${pkgver}/VERSION_PATCH
}

build() {
  cmake -B build -S ${pkgbase}-${pkgver} \
    -G 'Unix Makefiles' \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -Wno-dev
  cmake --build build
}

package_level-zero-headers() {
  pkgdesc+=" (headers)"
  #arch=(any) # Not supported for now, maybe later
  
  DESTDIR="${pkgdir}" cmake --install build
  install -Dm644 ${pkgbase}-${pkgver}/LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
  
  # remove loader files
  [ -d 'loader' ] && rm -rf loader
  install -d loader/lib
  mv "${pkgdir}"/usr/lib/*so* loader/lib
}

package_level-zero-loader() {
  pkgdesc+=" (loader)"
  depends=(gcc-libs)
  optdepends=('level-zero-driver: for packaged Level Zero driver')
  
  mv loader "${pkgdir}"/usr
  install -Dm644 ${pkgbase}-${pkgver}/LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
